Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt padding modifier fusion to avoid nested divs #253

Merged
merged 10 commits into from
Jun 21, 2021
Merged

Conversation

MaxDesiatov
Copy link
Collaborator

@MaxDesiatov MaxDesiatov commented Aug 5, 2020

This allows fusing nested .padding modifiers into a single div that sums up padding values from all these modifiers.

Before:

Text("text").padding(10).padding(20)

rendered to this (text styling omitted for brevity):

<div style="padding-top: 20.0px; padding-left: 20.0px; padding-bottom: 20.0px; padding-right: 20.0px;">
  <div style="padding-top: 10.0px; padding-left: 10.0px; padding-bottom: 10.0px; padding-right: 10.0px;">
    <span>text</span>
  </div>
</div>

Now it renders as

<div style="padding-top: 30.0px; padding-left: 30.0px; padding-bottom: 30.0px; padding-right: 30.0px;">
  <span>text</span>
</div>

I hope this approach could be applied to other modifier combinations where it makes sense (in separate PRs).

@MaxDesiatov MaxDesiatov added the refactor No user-visible functionality change label Aug 5, 2020
@MaxDesiatov MaxDesiatov marked this pull request as ready for review June 20, 2021 17:14
@@ -25,7 +25,7 @@ struct MetadataOffset<Pointee> {

func apply(to ptr: UnsafeRawPointer) -> UnsafePointer<Pointee> {
#if arch(wasm32)
return unsafeBitCast(offset, to: UnsafePointer<Pointee>.self)
return UnsafePointer<Pointee>(bitPattern: Int(offset))!
Copy link
Collaborator Author

@MaxDesiatov MaxDesiatov Jun 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a compiler warning that was previously produced on every build.

Copy link
Contributor

@foscomputerservices foscomputerservices left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice to have tests for these now. ✅

@MaxDesiatov MaxDesiatov merged commit e6c37a4 into main Jun 21, 2021
@MaxDesiatov MaxDesiatov deleted the padding-fusion branch June 21, 2021 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor No user-visible functionality change
Development

Successfully merging this pull request may close these issues.

2 participants